
from lib.api import *
import re
from lib.urls import *


def suite_setup():
    INFO('返回token')
    global auth_token
    auth_token = am.getToken()



class API_2038:
    name = 'API_2038'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 正确')
        response = requests.post(url_Target_Address+url_Point_getSubAppList,
                                 headers={
                                     "auth-token": auth_token
                                 }
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[12][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_2039:
    name = 'API_2039'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 过期')
        response = requests.post(url_Target_Address+url_Point_getSubAppList,
                                 headers={
                                     "auth-token":'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 }
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[13][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_2040:
    name = 'API_2040'       # 测试用例名字
    def teststeps(self):

        INFO('数据点监控接口：获取所有子系统接口 测试     #2.6')
        INFO('前置条件：token 为空')
        response = requests.post(url_Target_Address+url_Point_getSubAppList
                                 # headers={
                                 #     "auth-token":auth_token
                                 # }
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[13][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





